const tokenKey = 'nb_access_token';//键值
const userKey    = 'nb_wx_user'; // 用户信息
const uidKey = 'nb_uuid'; // 用户未登录前标识
const taskTagKey = 'nb_task_tag'; // 任务观察搜索选项
const taskTagVersion = 'nb_task_tag_version'; // 任务观察搜索选项
const taskAreaId = 'nb_task_area_id'; // 任务观察搜索选项
const keyPrefix = 'nb_public_'; // 公告存储前缀
// token
const getAccessToken = function(){
    let token= ''
    try {
        token = uni.getStorageSync(tokenKey);
        if(token === '') {
        }
        if(token.indexOf('Bearer') === -1) {
            token = 'Bearer '+token;
        }
    } catch (e) {}
    return token;
}
const setAccessToken = (access_token) => {
    try {uni.setStorageSync(tokenKey, access_token);return true;} catch (e) {return false;}
}
const clearAccessToken = function(){
    try {uni.removeStorageSync(tokenKey);} catch (e) {}
}
// userinfo
const setUser = (user)=>{
    try {uni.setStorageSync(userKey, user);return true;} catch (e) {return false;}
}
const getUser = function(){
    try {return uni.getStorageSync(userKey)} catch (e) {return false;}
}
const clearUser = function(){
    try {uni.removeStorageSync(userKey)} catch (e) {}
}
const setUuid = (uid) => {
    try {uni.setStorageSync(uidKey, uid); return true;} catch (e) { console.log("err:", e); return false; }
}
const getUuid = function(){
    try {return uni.getStorageSync(uidKey)} catch (e) {return false;}
}

const setTaskTagList = (tagList) => {
    try {uni.setStorageSync(taskTagKey, tagList); return true;} catch (e) { console.log("err:", e); return false; }
}
const getTaskTagList = function(){
    try {return uni.getStorageSync(taskTagKey)} catch (e) {return false;}
}

const setTaskTagVersion = (version) => {
    try {uni.setStorageSync(taskTagVersion, version); return true;} catch (e) { console.log("err:", e); return false; }
}
const getTaskTagVersion = function(){
    try {return uni.getStorageSync(taskTagVersion)} catch (e) {return false;}
}

const setAreaId = (area_id) => {
    try {uni.setStorageSync(taskAreaId, area_id); return true;} catch (e) { console.log("err:", e); return false; }
}
const getAreaId = function(){
    try {return uni.getStorageSync(taskAreaId)} catch (e) {return false;}
}

const setPubData = (public_key, value) => {
    try {uni.setStorageSync(keyPrefix+public_key, value); return true;} catch (e) { console.log("err:", e); return false; }
}
const getPubData = function(public_key){
    try {return uni.getStorageSync(keyPrefix+public_key)} catch (e) {return false;}
}

export default {
    getAccessToken,setAccessToken,clearAccessToken,getUser,setUser,clearUser,setUuid,getUuid,setTaskTagList,getTaskTagList,setTaskTagVersion,getTaskTagVersion,setAreaId,getAreaId,setPubData,getPubData
}